package com.step.ems.pages.home

import androidx.lifecycle.ViewModel
import com.step.ems.api.ApiService
import com.step.ems.common.launch
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
    private val apiService: ApiService
) : ViewModel() {
    private val _urgentNum = MutableStateFlow("")
    val urgentNum = _urgentNum.asStateFlow()

    private val _wbNum = MutableStateFlow("")
    val wbNum = _wbNum.asStateFlow()

    init {
        getData()
    }

    fun getData() {
        launch(
            delayTime = 200
        ) {
            val urgentNum = apiService.urgentNum().get()
            _urgentNum.value = urgentNum

            val wbNum = apiService.wbNum().get()
            _wbNum.value = wbNum
        }
    }
}